package com.roger.myHome.test;

import java.util.*;

public class RoundRobinDemo {
    private static Map<String, Integer> serverWeightMap = new HashMap();

    static {
        serverWeightMap.put("192.168.1.100",1);
        serverWeightMap.put("192.168.1.101",1);

        serverWeightMap.put("192.168.1.102",4);
        serverWeightMap.put("192.168.1.103",1);
        serverWeightMap.put("192.168.1.104",1);

        serverWeightMap.put("192.168.1.105",3);
        serverWeightMap.put("192.168.1.106",1);

        serverWeightMap.put("192.168.1.107",2);
        serverWeightMap.put("192.168.1.108",1);
        serverWeightMap.put("192.168.1.109",1);
        serverWeightMap.put("192.168.1.110",1);
    }

    public static String testRandom(){
        Map<String, Integer> serverMap = new HashMap<>();
        serverMap.putAll(serverWeightMap);

        Set<String> keySet = serverMap.keySet();
        ArrayList<String> keyList = new ArrayList<>();
        keyList.addAll(keySet);

        Random random = new Random();
        int randomPos = random.nextInt(keyList.size());

        String server = keyList.get(randomPos);

        return server;
    }

    public static int length (Double array[]) {
        return array.length;
    }

    private static Double average (Double array[]) {
        Double sum = 0D;
        int len = length(array);
//        for (int i = 0; i < len; i++) {
//            sum += array[i];
//        }

        int j = -1;
        while (j++ <= len + 1) {
            sum += array[j];
        }
        return sum;
    }

    private final static Integer ONE = 1;

    public static void main(String[] args) {
        List<Long> settlementList = new ArrayList<>();
        settlementList.add(1L);
        settlementList.add(2L);
        settlementList.add(3L);

        List<Long> settlementListCopy = new ArrayList<>(settlementList);

        List<Long> dbSettlementList = new ArrayList<>();
        dbSettlementList.add(1L);
        dbSettlementList.add(4L);
        dbSettlementList.add(5L);
        dbSettlementList.add(6L);

        List<Long> insetList = remove(settlementListCopy, dbSettlementList);
        List<Long> deleteList = remove(dbSettlementList, settlementList);
        //System.out.println(insetList);
        //System.out.println(deleteList);
        Double limit = 797436.6D;
        Double submit = 722979.18;
        int r = submit.compareTo(limit);
        System.out.println(r);
        System.out.println(Integer.valueOf(r).equals(ONE));
    }

    private static List<Long> remove(List<Long> list1 , List<Long> list2) {
        list1.removeAll(list2);
        return list1;
    }

}
